package com.ruoyi.result;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.result.Result;

import com.ruoyi.result.awardPersonal.mapper.ResultPersonalAwardMapper;


import com.ruoyi.result.awardStudent.mapper.ResultStudentAwardMapper;

import com.ruoyi.result.certificateinfo.mapper.ResultCertificateinfoMapper;

import com.ruoyi.result.copyright.mapper.ResultCopyrightMapper;

import com.ruoyi.result.horizontalProjects.mapper.ResultHorizontalProjectsMapper;

import com.ruoyi.result.longitudinalProjects.mapper.ResultLongitudinalProjectsMapper;

import com.ruoyi.result.material.mapper.ResultContinuingEducationMaterialMapper;

import com.ruoyi.result.other.mapper.ResultOtherMapper;
import com.ruoyi.result.papers.domain.ResultPapers;
import com.ruoyi.result.papers.mapper.ResultPapersMapper;
import com.ruoyi.result.patents.domain.ResultPatents;
import com.ruoyi.result.patents.mapper.ResultPatentsMapper;
import com.ruoyi.result.publication.domain.ResultPublication;
import com.ruoyi.result.publication.mapper.ResultPublicationMapper;
import com.ruoyi.result.report.domain.ResultReport;
import com.ruoyi.result.report.mapper.ResultReportMapper;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.impl.SysUserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/result/summary")
@Api(tags = "各模块数据统计接口")
@CrossOrigin
public class SummaryController {

    @Autowired
    private ResultPersonalAwardMapper resultPersonalAwardMapper;
    @Autowired
    private ResultStudentAwardMapper resultStudentAwardMapper;
    @Autowired
    private ResultCertificateinfoMapper resultCertificateinfoMapper;
    @Autowired
    private ResultCopyrightMapper resultCopyrightMapper;
    @Autowired
    private ResultHorizontalProjectsMapper resultHorizontalProjectsMapper;
    @Autowired
    private ResultLongitudinalProjectsMapper resultLongitudinalProjectsMapper;
    @Autowired
    private ResultContinuingEducationMaterialMapper resultContinuingEducationMaterialMapper;
    @Autowired
    private ResultOtherMapper resultOtherMapper;
    @Autowired
    private ResultPapersMapper resultPapersMapper;
    @Autowired
    private ResultPatentsMapper resultPatentsMapper;
    @Autowired
    private ResultPublicationMapper resultPublicationMapper;
    @Autowired
    private ResultReportMapper resultReportMapper;


    @Autowired
    private ISysUserService iSysUserService;
    /**
     * 查询每个模块的数量
     */
    @GetMapping("/getCount")
    @ApiOperation("查询各模块数据数量")
    @PreAuthorize("@ss.hasPermi('data:center')")
    public AjaxResult getCount() {
        try {
            // 使用 MyBatis 查询每个模块的数量
            long personalAwardCount = resultPersonalAwardMapper.selectCount();
            long studentAwardCount = resultStudentAwardMapper.selectCount();
            long certificateCount = resultCertificateinfoMapper.selectCount();
            long copyrightCount = resultCopyrightMapper.selectCount();
            long horizontalProjectsCount = resultHorizontalProjectsMapper.selectCount();
            long longitudinalProjectsCount = resultLongitudinalProjectsMapper.selectCount();
            long continuingEducationCount = resultContinuingEducationMaterialMapper.selectCount();
            long otherCount = resultOtherMapper.selectCount();
            long papersCount = resultPapersMapper.selectCountNumber();
            long patentsCount = resultPatentsMapper.selectCount();
            long publicationCount = resultPublicationMapper.selectCount();
            long reportCount = resultReportMapper.selectCount();

            // 构造返回数据的 Map
            Map<String, Long> countMap = new HashMap<>();
            countMap.put("personalAwardCount", personalAwardCount);
            countMap.put("studentAwardCount", studentAwardCount);
            countMap.put("certificateCount", certificateCount);
            countMap.put("copyrightCount", copyrightCount);
            countMap.put("horizontalProjectsCount", horizontalProjectsCount);
            countMap.put("longitudinalProjectsCount", longitudinalProjectsCount);
            countMap.put("continuingEducationCount", continuingEducationCount);
            countMap.put("otherCount", otherCount);
            countMap.put("papersCount", papersCount);
            countMap.put("patentsCount", patentsCount);
            countMap.put("publicationCount", publicationCount);
            countMap.put("reportCount", reportCount);

            // 返回 AjaxResult 成功响应
            return AjaxResult.success(countMap);
        } catch (Exception e) {
            log.error("查询模块数量失败", e);
            // 返回 AjaxResult 错误响应
            return AjaxResult.error("查询失败");
        }
    }



}

